﻿using System.Security.AccessControl;
using System.IO;

namespace Sex
{
    public partial class Sex : System.Web.UI.Page
    {
        public class ListPermissions : MyList
        {
            public ListPermissions(State MyState)
                : base(MyState, "Permissions")
            {
                DirectorySecurity Rights = Directory.GetAccessControl(MyState.CurrentPathAbs);
                int i = 0;
                foreach (FileSystemAccessRule fileSystemAccessRule in Rights.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
                {
                    string Key = fileSystemAccessRule.IdentityReference.Value.ToString();
                    string Value = fileSystemAccessRule.FileSystemRights.ToString();
                    if (!ContainsKey(Key)) // avoid duplicate keys
                    {
                        Add(i.ToString().PadLeft(2, '0').PadRight(3) + Key, Value);
                        i++;
                    }
                }
            }
        }
    }
}